import socket
import threading

bind_ip = "0.0.0.0"
bind_port = 9999

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

server.bind((bind_ip, bind_port))

# set max connect number 5
server.listen(5)

print('[*] Listening on {}:{}'.format(bind_ip, bind_port))


# handle client thread
def handle_client(client_socket):
    # print response content
    request = client_socket.recv(1024)
    print('[*] Received: {}'.format(request))

    # return response data
    client_socket.send('ack!'.encode('utf-8'))
    client_socket.close()


while True:
    client, addr = server.accept()
    print('[*] Accepted connection from: {}:{}'.format(addr[0], addr[1]))

    client_thread = threading.Thread(target=handle_client, args=(client,))
    client_thread.start()
